/**
 * 
 */
package com.googlecode.dynargs.extractor;

import java.util.Arrays;

import com.googlecode.dynargs.model.type.EnumerationType;

/**
 * @author Federico De Faveri defaveri@gmail.com
 *
 */
public class EnumerationExtractor implements TypeExtractor<EnumerationType> {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean canExtract(TypeToken type) {
		Class<?> clazz = type.getRawType();
		return clazz.isEnum();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public EnumerationType extract(ModelExtractor modelExtractor, TypeToken type) {
		Class<?> clazz = type.getRawType();
		String id = clazz.getName();
		
		Object[] constants = clazz.getEnumConstants();
		EnumerationType enumeration = new EnumerationType(id, Arrays.asList(constants));

		return enumeration;
	}

}
